<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Login and Registration</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      background-color: #f4f4f4;
      display: flex;
      justify-content: center;
      align-items: center;
      height: 100vh;
      margin: 0;
    }

  .container {
      background-color: white;
      padding: 20px;
      border-radius: 5px;
      box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
      width: 350px;
    }

    h2 {
      text-align: center;
    }

    label {
      display: block;
      margin-bottom: 5px;
    }

    input {
      width: 100%;
      padding: 8px;
      margin-bottom: 15px;
      border: 1px solid #ccc;
      border-radius: 3px;
    }

    button {
      background-color: #007bff;
      color: white;
      padding: 10px 15px;
      border: none;
      border-radius: 3px;
      cursor: pointer;
      width: 100%;
    }

    button:hover {
      background-color: #0056b3;
    }

  .link {
      text-align: center;
      margin-top: 10px;
    }
  </style>
</head>

<body>
  <div class="container">
    <h2>Login</h2>
    <form id="loginForm">
      <label for="username">Username:</label>
      <input type="text" id="username" required>
      <label for="password">Password:</label>
      <input type="password" id="password" required>
      <button type="submit">Login</button>
    </form>
    <div class="link">
      <a href="#" onclick="showRegistration()">Don't have an account? Register here</a>
    </div>
  </div>

  <script>
	function showRegistration() {
      // 这里可以添加跳转到注册页面的逻辑，比如修改当前页面的URL或者显示隐藏的注册表单
      window.location.href ='/homepage/register/register.html';
    }
	
    document.getElementById('loginForm').addEventListener('submit', function (e) {
      e.preventDefault();
      var username = document.getElementById('username').value;
      var password = document.getElementById('password').value;
      if (username && password) {
        fetch('/homepage/login/src/loginMain.exe', {
          method: 'POST',
          headers: {
            'Content-Type': 'application/json'
          },
          body: JSON.stringify({ username: username, password: password })
        })
         .then(response => response.json())
         .then(data => {
            <!-- const resultDisplay = document.getElementById('result-display'); -->
            if (data.success) {
              //resultDisplay.innerHTML = `<p>登录成功！欢迎 ${data.message}。</p>`;
				window.location.href = '/homepage/gameDaTing/gameDaTing.html';
            } else {
              //resultDisplay.innerHTML = `<p>登录失败：${data.message}</p>`;
				alert('Login failed. Please check your username and password.');
			}
          });
      } else {
        alert('Please enter both username and password.');
      }
    });
  </script>
</body>

</html>
